//
//  D2DrawerLeftViewController.m
//  STBasicsApp
//
//  Created by jerry on 2019/5/3.
//  Copyright © 2019 jerry. All rights reserved.
//

#import "D2DrawerLeftViewController.h"
#import "UIViewController+MMDrawerController.h"
#import "D2DrawerShowViewController.h"

@interface D2DrawerLeftViewController ()

@end

@implementation D2DrawerLeftViewController

-(id)init{
    self = [super init];
    if(self){
        [self setRestorationIdentifier:@"MMLeftSideDrawerController"];
    }
    return self;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSLog(@"Left will appear");
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    NSLog(@"Left did appear");
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    NSLog(@"Left will disappear");
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    NSLog(@"Left did disappear");
}

-(void)viewDidLoad{
    [super viewDidLoad];
    [self setTitle:@"Left Drawer"];
    self.view.backgroundColor = kGragColor;
}

#pragma mark - UITableViewDataSource


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text =[NSString stringWithFormat:@"Left-Demo%ld",indexPath.row];
    cell.backgroundColor = kGragColor;
    return cell;
}


#pragma mark - UITableViewDelegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    D2DrawerShowViewController *showVC = [[D2DrawerShowViewController alloc]init];
    showVC.title = [NSString stringWithFormat:@"Left-Demo%ld",indexPath.row];
    
    //拿到我们的LitterLCenterViewController，让它去push
    UINavigationController* nav = (UINavigationController*)self.mm_drawerController.centerViewController;
    if (nav && [nav isKindOfClass:[UINavigationController class]]) {
      [nav pushViewController:showVC animated:NO];
    }
    
    //当我们push成功之后，关闭我们的抽屉
    [self.mm_drawerController closeDrawerAnimated:YES completion:^(BOOL finished) {
        //设置打开抽屉模式为MMOpenDrawerGestureModeNone，也就是没有任何效果。
        [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
    }];
}


@end
